%
( *************************************************************************** )
( * Biquad tool                                                             * )
( * Metrical RS274/NGC program                                              * )
( * Copyright 2009 Michael Buesch <mb@bu3sch.de>                            * )
( * Licensed under the GNU/GPL version 3                                    * )
( *************************************************************************** )

#100 = 3.0		( Cutter radius; must be 3 +-0.1 )
#101 = 4000		( Roughing speed in min^-1 )
#102 = 4000		( Finecut speed in min^-1 )
#103 = 350		( Roughing feed in mm/min )
#104 = 350		( Finecut feed in mm/min )
#105 = -5		( Z depth )
#106 = 1		( Z stepping while roughing )
#107 = 0.1		( X/Y stepping in finecut )
#108 = 0.05		( Roughing G64 tolerance )
#109 = 0.01		( Finecut G64 tolerance )

G17 G40 G49 G80 G90 G94 G61 G21


O3 sub ( Square subroutine. #1=X-offset, #2=Y-offset, #3=G42.1-offset )
	G0 X[-20 + #1] Y[-25 + #2]
	G42.1 D[[#100 + #3] * 2]
	G1 X[-24.388 + #1] Y[-23.433 + #2]
	G1 X[-1.909 + #1] Y[-0.955 + #2]
	G3 X[-1.909 + #1] Y[0.955 + #2] I-0.955 J0.955
	G1 X[-20.612 + #1] Y[19.658 + #2]
	G3 X[-22.521 + #1] Y[19.658 + #2] I-0.955 J-0.955
	G1 X[-41.224 + #1] Y[0.955 + #2]
	G3 X[-41.224 + #1] Y[-0.955 + #2] I0.955 J-0.955
	G1 X[-22.521 + #1] Y[-19.658 + #2]
	G3 X[-20.612 + #1] Y[-19.658 + #2] I0.955 J0.955
	G40 G1 X[-20 + #1] Y[-25 + #2]
O3 endsub

O1 sub ( Roughing subroutine )
	G64 P#108
	G0 X-51 Y-23 Z5 S#101 F#103

	M3
	#200 = 0
	O11 while [ 1 ]
		#200 = [#200 - #106]
		O12 if [#200 lt #105]
			#200 = #105
		O12 endif
		G0 Z#200

		( Outer frame )
		G1 X-24.5
		G1 Y-23.5
		G1 X-18.5
		G1 Y-23
		G1 X18.5
		G1 Y-23.5
		G1 X24.5
		G1 Y-23
		G1 X45.5
		G1 Y23
		G1 X24.5
		G1 Y23.5
		G1 X18.5
		G1 Y23
		G1 X-18.5
		G1 Y23.5
		G1 X-24.5
		G1 Y23
		G1 X-45.5
		G1 Y-23

		( Lower left )
		G0 X-37.988
		G1 X-45.5 Y-15.488
		G0 Y-8.417
		G1 X-30.917 Y-23
		G0 Y-25

		( Lower center )
		G0 X-12.217
		G0 Y-23
		G1 X0 Y-10.783
		G1 X12.217 Y-23
		G0 X5.146
		G1 X0 Y-17.854
		G1 X-5.146 Y-23
		G0 Y-25 X12

		( Lower right )
		G0 X30.917
		G0 Y-23
		G1 X45.5 Y-8.417
		G0 Y-15.488
		G1 X37.988 Y-23
		G0 X45.5 Y-15.488

		( Upper right )
		G0 Y8.417
		G1 X30.917 Y23
		G0 X37.988
		G1 X45.5 Y15.488
		G0 X31 Y25

		( Upper center )
		G0 X12.217
		G0 Y23
		G1 X0 Y10.783
		G1 X-12.217 Y23
		G0 X-5.146
		G1 X0 Y17.854
		G1 X5.146 Y23
		G0 X-12 Y25

		( Upper left )
		G0 X-30.917
		G0 Y23
		G1 X-45.5 Y8.417
		G0 Y15.488
		G1 X-37.988 Y23

		G0 X-45.5 Y15.488
		G0 Y-8.417
		G0 X-30.917 Y-23
		G0 X-20 Y-25

		( Left square roughing )
		O3 call [0] [0] [0.3]
		( Right square roughing )
		G0 X[-20 + 43.134] Y-25
		O3 call [43.134] [0] [0.3]

		O13 if [#200 eq #105]
			O11 break
		O13 endif
		G0 X-51 Y-25
		G0 Y-23
	O11 endwhile
O1 endsub

O2 sub ( Finecut subroutine )
	G64 P#109
	( FIXME do a run with Z raised by 0.3 )

	( Left square )
	G0 X-20 Y-25 Z#105 S#102 F#104
	M3
	#200 = 0.30
	O21 while [ 1 ]
		#200 = [#200 - #107]
		O22 if [#200 lt 0]
			#200 = 0
		O22 endif

		O3 call [0] [0] [#200]

		O23 if [#200 eq 0]
			O21 break
		O23 endif
	O21 endwhile

	( Right square )
	G0 X[-20 + 43.134] Y-25 Z#105 S#102 F#104
	#200 = 0.30
	O25 while [ 1 ]
		#200 = [#200 - #107]
		O26 if [#200 lt 0]
			#200 = 0
		O26 endif

		O3 call [43.134] [0] [#200]

		O27 if [#200 eq 0]
			O25 break
		O27 endif
	O25 endwhile
O2 endsub


T1 M6
G54 G0 X0 Y0 Z5 S#2

O1 call ( Call roughing )
O2 call ( Call finecut )

G0 Z5 M5
M30

%
vim: syntax=rs274ngc ts=4
